// 输入​
let arr1 = [1, 2,8];
let arr2 = [-1, 2, 8, 9];
function collectSort(arr1, arr2) {
    let result = []
    let i = 0
    let j = 0

    while (i < arr1.length && j < arr2.length) {
        if (arr1[i] < arr2[j]) {
            result.push(arr1[i])
            i++
        } else if (arr1[i] > arr2[j]) {
            result.push(arr2[j])
            j++
        } else {
            result.push(arr1[i])
            i++
            j++
        }
    }
    if (i === arr1.length) {
        result = result.concat(arr2.slice(i))
    }
    if (j === arr2.length) {
        result = result.concat(arr1.slice(j))
    }
    console.log(result)
}

collectSort(arr1, arr2)
// 输出
// [-1, 1, 2, 8, 9]
